package com.niit.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import com.niit.dao.LoginDao;
import com.niit.utils.ConnectionUtil;

public class LoginDaoImpl implements LoginDao {
	@Override
	public boolean login(String uname, String pwd) {
		String sql = "select * from sys_user where username = ?";
		Connection conn = null;
		PreparedStatement psmt = null;
		ResultSet rs = null;
		try {
			conn = ConnectionUtil.getConnection();
			psmt = conn.prepareStatement(sql);
			psmt.setString(1, uname);
			rs = psmt.executeQuery();
			if(rs.next()) {
				String dbpwd = rs.getString("pwd");
				if(pwd.equals(dbpwd))
					return true;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}finally {
			ConnectionUtil.close(conn, psmt, rs);
		}
		return false;
	}
}
